﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RecruitStudents.Utility;
using RecruitStudents.Utility.Model;
using RecruitStudents.Utility.Helper;
using RecruitStudents.Utility.Json;
using RecruitStudents.Utility.Const;

namespace RecruitStudents.Client.BLL
{
    public class ServiceBase
    {
        WS_Base.BaseService baseService = new WS_Base.BaseService();
        WS_Base.MySoapHeader objHeader = new WS_Base.MySoapHeader();
        internal ServiceBase()
        {
            objHeader.Username = "admin";
            objHeader.Password = "xy";
            baseService.MySoapHeaderValue = objHeader;
        }

        #region 数据字典维护
        internal DataTable GetDicMain()
        {
            return baseService.GetDicMain().ToDataTable();
        }

        internal DataTable GetDicValueByTableName(string strTableName)
        {
            if (strTableName.IsNullOrEmptyString())
            {
                return null;
            }
            using (DataTable result = baseService.GetDicValueByTableName(strTableName, string.Empty).ToDataTable())
            {
                if (result != null)
                {
                    foreach (DataRow dr in result.Rows)
                    {
                        if (dr["IsActive"].ToSafeString() == "1")
                        {
                            dr["IsActive"] = "有效";
                        }
                        else
                        {
                            dr["IsActive"] = "无效";
                        }
                    }
                }
                return result;
            }
        }

        internal DataTable GetDicValue(string strTableName, string strDicNo)
        {
            return baseService.GetDicValue(strTableName, strDicNo).ToDataTable();
        }

        internal bool SaveDicValue(string strTableName, string strDicNo, string strDicName, string strIsActive)
        {
            try
            {
                var result = baseService.SaveDicValue(strTableName, strDicNo, strDicName, strIsActive).ToList<JsonMessage>();
                if (result.State.ToLower() == "false")
                {
                    DevHelper.ShowErrorMessageBox(result.Msg);
                    return false;
                }
                else
                {
                    DevHelper.ShowInfoMessageBox(result.Msg);
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }

        #endregion

        #region 用户管理
        internal bool SaveUser(TB_Sys_User model)
        {
            try
            {
                string strJson = model.ToJson();
                DevHelper.ShowWaiting();
                var obj = baseService.SaveUser(strJson);
                var result = obj.ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    DevHelper.ShowErrorMessageBox(result.Msg);
                    return false;
                }
                else
                {
                    DevHelper.ShowInfoMessageBox(result.Msg);
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }

        internal TB_Sys_User GetUserModel(string id)
        {
            DevHelper.ShowWaiting();
            var obj = baseService.GetUserModel(id);
            TB_Sys_User result = obj.ToList<TB_Sys_User>();
            DevHelper.HideWaiting();
            return result;
        }

        internal DataTable GetUserTable(string strLoginName, string strName, string strType)
        {
            DevHelper.ShowWaiting();
            using (DataTable result = baseService.GetUserTable(strLoginName, strName, strType).ToDataTable())
            {
                if (result != null)
                {
                    foreach (DataRow dr in result.Rows)
                    {
                        dr["Type"] = Utility.Const.ConstAppConfig.DicUserType[dr["Type"].ToSafeString()];
                        if (dr["IsActive"].ToSafeString() == "1")
                        {
                            dr["IsActive"] = "有效";
                        }
                        else
                        {
                            dr["IsActive"] = "无效";
                        }
                    }
                }
                return result;
            }
        }

        internal bool DeleteUser(string strID)
        {
            try
            {
                DevHelper.ShowWaiting();
                var result = baseService.DeleteUser(strID).ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    DevHelper.ShowErrorMessageBox(result.Msg);
                    return false;
                }
                else
                {
                    DevHelper.ShowInfoMessageBox(result.Msg);
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }
        #endregion

        #region 角色管理

        internal bool SaveRoleAuth(List<TB_Sys_RoleAuth> list)
        {
            try
            {
                string strJson = list.ToJson();
                DevHelper.ShowWaiting();
                var result = baseService.SaveRoleAuth(strJson).ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    DevHelper.ShowErrorMessageBox(result.Msg);
                    return false;
                }
                else
                {
                    if (list != null && list.Count > 0)
                    {
                        strJson = list.ToJson<List<TB_Sys_RoleAuth>>();
                        baseService.SaveRoleAuth(strJson).ToList<JsonMessage>();
                    }
                    DevHelper.ShowInfoMessageBox(result.Msg);
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }

        internal bool SaveRole(TB_Sys_Role model, List<TB_Sys_RoleAuth> list)
        {
            try
            {
                string strJson = model.ToJson();
                DevHelper.ShowWaiting();
                var result = baseService.SaveRole(strJson).ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    DevHelper.ShowErrorMessageBox(result.Msg);
                    return false;
                }
                else
                {
                    if (list != null && list.Count > 0)
                    {
                        strJson = list.ToJson<List<TB_Sys_RoleAuth>>();
                        baseService.SaveRoleAuth(strJson).ToList<JsonMessage>();
                    }
                    DevHelper.ShowInfoMessageBox(result.Msg);
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }

        internal TB_Sys_Role GetRoleModel(string id)
        {
            DevHelper.ShowWaiting();
            var result = baseService.GetRoleModel(id).ToList<TB_Sys_Role>();
            DevHelper.HideWaiting();
            return result;
        }

        internal DataTable GetRoleTable(string strRoleName, string strIsActive)
        {
            DevHelper.ShowWaiting();
            var result = baseService.GetRoleTable(strRoleName, strIsActive).ToDataTable();
            if (result != null)
            {
                foreach (DataRow dr in result.Rows)
                {
                    if (dr["IsActive"].ToSafeString() == "1")
                    {
                        dr["IsActive"] = "有效";
                    }
                    else
                    {
                        dr["IsActive"] = "无效";
                    }
                }
            }
            return result;
        }

        internal bool DeleteRole(string strDataID)
        {
            try
            {
                DevHelper.ShowWaiting();
                var result = baseService.DeleteRole(strDataID).ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    DevHelper.ShowErrorMessageBox(result.Msg);
                    return false;
                }
                else
                {
                    DevHelper.ShowInfoMessageBox(result.Msg);
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }

        internal DataTable GetModuleTable()
        {
            return baseService.GetModuleTable().ToDataTable();
        }

        internal DataTable GetRoleAuthModuleTable(string strRoleID)
        {
            return baseService.GetRoleAuthModuleTable(strRoleID).ToDataTable();
        }
        #endregion

        #region Mac管理
        internal DataTable GetExamMacByRoomTable(string strExamYear)
        {
            return baseService.GetExamMacByRoomTable(strExamYear).ToDataTable();
        }
        internal DataTable GetExamMacTable(bool chkSFTY, string strMacName)
        {
            string strSFTY = string.Empty;
            if (chkSFTY)
            {
                strSFTY = "1";
            }
            else
            {
                strSFTY = "0";
            }
            using (DataTable result = baseService.GetExamMacTable("", "", strSFTY, strMacName).ToDataTable())
            {
                if (result != null)
                {
                    foreach (DataRow dr in result.Rows)
                    {
                        if (dr["IsActive"].ToSafeString() == "1")
                        {
                            dr["IsActive"] = "有效";
                        }
                        else
                        {
                            dr["IsActive"] = "无效";
                        }
                        dr["MachineType"] = ConstAppConfig.DicPadType[dr["MachineType"].ToSafeString()];
                    }
                }
                return result;
            }
        }
        internal TB_Exam_Mac GetExamMacModel(string strMacID)
        {
            return baseService.GetExamMacModel(strMacID).ToList<TB_Exam_Mac>();
        }
        internal bool SaveExamMac(TB_Exam_Mac model)
        {
            try
            {
                string strJson = model.ToJson();
                DevHelper.ShowWaiting();
                var obj = baseService.SaveExamMac(strJson);
                var result = obj.ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    DevHelper.ShowErrorMessageBox(result.Msg);
                    return false;
                }
                else
                {
                    DevHelper.ShowInfoMessageBox(result.Msg);
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }
        #endregion

        #region 考官管理
        /// <summary>
        /// 获取考官列表，下拉框
        /// </summary>
        /// <param name="strYear"></param>
        /// <param name="strRoomID"></param>
        /// <param name="strSpec"></param>
        /// <returns></returns>
        internal DataTable GetExaminerTableByDropDown(string strYear, string strRoomID, string strSpec)
        {
            return baseService.GetExaminerTableByDropDown(strYear, strRoomID, strSpec).ToDataTable();
        }
        /// <summary>
        /// <b><i>获取考官列表</i></b>
        /// </summary>
        /// <param name="strLoginName">登录名</param>
        /// <param name="strName">姓名</param>
        /// <param name="strType">考官类别</param>
        /// <param name="strSSZY">所属专业</param>
        /// <param name="strYear">年份</param>
        /// <returns></returns>
        internal DataTable GetExaminerTable(string strLoginName, string strName, string strType, string strSSZY, string strYear)
        {
            using (DataTable result = baseService.GetExaminerTable(strLoginName, strName, strType, strSSZY, strYear).ToDataTable())
            {
                if (result != null)
                {
                    foreach (DataRow dr in result.Rows)
                    {
                        if (dr["IsActive"].ToSafeString() == "1")
                        {
                            dr["IsActive"] = "有效";
                        }
                        else
                        {
                            dr["IsActive"] = "无效";
                        }
                    }
                }
                return result;
            }
        }

        /// <summary>
        /// 获取考官实体对象
        /// </summary>
        /// <param name="strExaminerID"></param>
        /// <returns></returns>
        internal TB_Exam_Examiner GetExaminerModel(string strExaminerID)
        {
            return baseService.GetExaminerModel(strExaminerID).ToList<TB_Exam_Examiner>();
        }

        /// <summary>
        /// 保存考官实体对象 返回JsonMessage数据
        /// </summary>
        /// <param name="strJson"></param>
        /// <returns></returns>
        internal bool SaveExaminer(TB_Exam_Examiner model)
        {
            try
            {
                DevHelper.ShowWaiting();
                string strJson = model.ToJson();
                var result = baseService.SaveExaminer(strJson).ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    DevHelper.ShowErrorMessageBox(result.Msg);
                    return false;
                }
                else
                {
                    DevHelper.ShowInfoMessageBox(result.Msg);
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }
        #endregion

        #region 考官考场关联
        /// <summary>
        /// 获取考官考场DataTable数据
        /// </summary>
        /// <param name="strExamRoomNO"></param>
        /// <param name="strExaminerID"></param>
        /// <param name="strExamYear"></param>
        /// <returns></returns>
        internal DataTable GetExaminerRoomDataTable(string strExamRoomNO, string strExaminerID, string strExamYear)
        {
            using (DataTable result = baseService.GetExaminerRoomDataTable(strExamRoomNO, strExaminerID, strExamYear).ToDataTable())
            {
                if (result != null)
                {
                    result.Columns.Add("RoomTeacher");
                    result.Columns.Add("RoomTeacherID");
                    foreach (DataRow dr in result.Rows)
                    {
                        dr["RoomTeacher"] = dr["ExamRoomName"] + "-" + dr["ExaminerName"];
                        dr["RoomTeacherID"] = dr["ExaminerID"] + "|" + dr["ExamRoomNO"];
                    }
                }
                return result;
            }
        }
        /// <summary>
        /// 删除考官实体对象
        /// </summary>
        /// <param name="strExamRoomNO"></param>
        /// <param name="strExaminerID"></param>
        /// <param name="strExamYear"></param>
        /// <returns></returns>
        internal bool DeleteExaminerRoomMapping(string strExamRoomNO, string strExaminerID, string strExamYear)
        {
            DevHelper.ShowWaiting();
            var result = baseService.DeleteExaminerRoomMapping(strExamRoomNO, strExaminerID, strExamYear).ToList<JsonMessage>();
            DevHelper.HideWaiting();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                return true;
            }
        }

        /// <summary>
        /// 保存考官考场实体对象
        /// </summary>
        /// <param name="strJson"></param>
        /// <returns></returns>
        internal bool SaveExaminerRoomMapping(List<TB_Exam_ExamRoomExaminerMapping> list)
        {
            try
            {
                DevHelper.ShowWaiting();
                string strJson = list.ToJson();
                var result = baseService.SaveExaminerRoomMapping(strJson).ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    DevHelper.ShowErrorMessageBox(result.Msg);
                    return false;
                }
                else
                {
                    DevHelper.ShowInfoMessageBox(result.Msg);
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }
        #endregion

        #region 考生号相关
        internal DataTable GetDicNMTSignUpTable(string strName)
        {
            return baseService.GetDicNMTSignUpTable(strName).ToDataTable();
        }

        internal TB_Dic_NMT_SignUp GetDicNMTSignUpModel(string strNativePlaceNO)
        {
            return baseService.GetDicNMTSignUpModel(strNativePlaceNO).ToList<TB_Dic_NMT_SignUp>();
        }
        internal bool SaveDicNMTSignUp(TB_Dic_NMT_SignUp model)
        {
            string strJson = model.ToJson();
            var obj = baseService.SaveDicNMTSignUp(strJson);
            var result = obj.ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }
        #endregion

        #region 专业相关
        internal TB_Sys_SpecialityKinds GetSpecialityKindsModel(string strSpecialityKindsNO)
        {
            return baseService.GetSpecialityKindsModel(strSpecialityKindsNO).ToList<TB_Sys_SpecialityKinds>();
        }
        internal bool DeleteSpecialityKinds_Detail_Sub(string strSpecialityKindsNo_Detail, string SpecialityKindsNo_Detail_Sub)
        {
            var obj = baseService.DeleteSpecialityKinds_Detail_Sub(strSpecialityKindsNo_Detail, SpecialityKindsNo_Detail_Sub);
            var result = obj.ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }
        internal bool DeleteSpecialityKindsDetail(string strExamPlaceNO, string strSpecialityKindsNo_Detail)
        {
            var obj = baseService.DeleteSpecialityKinds_Detail(strExamPlaceNO, strSpecialityKindsNo_Detail);
            var result = obj.ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }
        internal DataTable GetSpecialityKinds_Detail_SubDataTable(string SpecialityKindsDetailNO, string IsActive)
        {
            return baseService.GetSpecialityKinds_Detail_SubDataTable(SpecialityKindsDetailNO, IsActive).ToDataTable();
        }
        internal DataTable GetSpecialityKindsDetailTable(string strSpecialityKindsNO)
        {
            return baseService.GetSpecialityKindsDetailTable(strSpecialityKindsNO).ToDataTable();
        }
        internal DataTable GetSpecialityKindsTable(string strSpecialityKindsNO, string strSpecialityKindsName, string strIsActive, string strIsSchool)
        {
            using (DataTable dt = baseService.GetSpecialityKindsDataTable(SessionerHelper.SystemYear, strSpecialityKindsNO, strSpecialityKindsName, strIsActive, strIsSchool).ToDataTable())
            {
                if (dt != null)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        dr["LimitSex"] = Utility.Const.ConstAppConfig.DicLimitSexType[dr["LimitSex"].ToSafeString()];
                        if (dr["IsSchool"].ToSafeString() == "1")
                        {
                            dr["IsSchool"] = "是";
                        }
                        else
                        {
                            dr["IsSchool"] = "否";
                        }
                        if (dr["IsActive"].ToSafeString() == "1")
                        {
                            dr["IsActive"] = "是";
                        }
                        else
                        {
                            dr["IsActive"] = "否";
                        }
                    }
                }
                return dt;
            }

        }
        internal bool SaveSpecialityKinds(TB_Sys_SpecialityKinds model)
        {
            try
            {
                string strJson = model.ToJson();
                DevHelper.ShowWaiting();
                var obj = baseService.SaveSpecialityKinds(strJson);
                var result = obj.ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    DevHelper.ShowErrorMessageBox(result.Msg);
                    return false;
                }
                else
                {
                    DevHelper.ShowInfoMessageBox(result.Msg);
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }
        internal bool SaveSpecialityKindsDetail(TB_Sys_SpecialityKinds_Detail model)
        {
            try
            {
                string strJson = model.ToJson();
                DevHelper.ShowWaiting();
                var obj = baseService.SaveSpecialityKinds_Detail(strJson);
                var result = obj.ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    DevHelper.ShowErrorMessageBox(result.Msg);
                    return false;
                }
                else
                {
                    DevHelper.ShowInfoMessageBox(result.Msg);
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }
        internal bool SaveSpecialityKinds_Detail_Sub(TB_Sys_SpecialityKinds_Detail_Sub model)
        {
            try
            {
                string strJson = model.ToJson();
                DevHelper.ShowWaiting();
                var obj = baseService.SaveSpecialityKinds_Detail_Sub(strJson);
                var result = obj.ToList<JsonMessage>();
                DevHelper.HideWaiting();
                if (result.State.ToLower() == "false")
                {
                    DevHelper.ShowErrorMessageBox(result.Msg);
                    return false;
                }
                else
                {
                    DevHelper.ShowInfoMessageBox(result.Msg);
                    return true;
                }
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("操作数据出现错误:" + ex.Message);
                DevHelper.HideWaiting();
                return false;
            }
        }
        internal DataTable GetSignUpStudentsType()
        {
            return baseService.GetSignUpStudentsType().ToDataTable();
        }
        #endregion

        #region 考点相关 
        internal bool SaveSysExamPlaceLimit(List<TB_Sys_ExamPlace_Limit> model)
        {
            string strJson = model.ToJson();
            var obj = baseService.SaveSysExamPlaceLimit(strJson);
            var result = obj.ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }
        internal bool SaveSysExamPlace(TB_Sys_ExamPlace model)
        {
            string strJson = model.ToJson();
            var obj = baseService.SaveSysExamPlace(strJson);
            var result = obj.ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                return true;
            }
        }
        internal DataTable GetSysExamPlaceDataTable(string strExamProvince, string strExamPlaceName, string strIsActive)
        {
            using (DataTable result = baseService.GetSysExamPlaceDataTable(strExamProvince, strExamPlaceName, strIsActive).ToDataTable())
            {
                if (result != null)
                {
                    foreach (DataRow dr in result.Rows)
                    {
                        if (dr["IsActive"].ToSafeString() == "1")
                        {
                            dr["IsActive"] = "有效";
                        }
                        else
                        {
                            dr["IsActive"] = "无效";
                        }
                    }
                }
                return result;
            }
        }
        internal DataTable GetSysExamPlace_Limit(string strExamPlaceNO)
        {
            return baseService.GetSysExamPlace_Limit(strExamPlaceNO).ToDataTable();
        }
        internal TB_Sys_ExamPlace GetSysExamPlaceModel(string strExamPlaceNO)
        {
            return baseService.GetSysExamPlaceModel(strExamPlaceNO).ToList<TB_Sys_ExamPlace>();
        }
        internal bool DeleteSysExamPlace(string strExamPlaceNO)
        {
            var obj = baseService.DeleteSysExamPlace(strExamPlaceNO);
            var result = obj.ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }
        #endregion

        #region 算分规则
        internal DataTable GetExamCalculateTypeFormTable(string strExamYear)
        {
            return baseService.GetExamCalculateTypeFormTable(strExamYear).ToDataTable();
        }

        internal TB_Rule_CalculateScore GetExamCalculateTypeFormModel(string strCalculateScoreID)
        {
            return baseService.GetExamCalculateTypeFormModel(strCalculateScoreID).ToList<TB_Rule_CalculateScore>();
        }

        internal bool SaveExamCalculateTypeForm(TB_Rule_CalculateScore model)
        {
            string strJson = model.ToJson();
            var obj = baseService.SaveExamCalculateTypeForm(strJson);
            var result = obj.ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        internal bool DeleteExamCalculateTypeForm(string strCalculateScoreID)
        {
            var obj = baseService.DeleteExamCalculateTypeForm(strCalculateScoreID);
            var result = obj.ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        internal DataTable GetExamCalculateTypeFormTable_Detail(string strCalculateScoreID)
        {
            DevHelper.ShowWaiting();

            using (DataTable result = baseService.GetExamCalculateTypeFormTable_Detail(strCalculateScoreID).ToDataTable())
            {
                if (result != null)
                {
                    foreach (DataRow dr in result.Rows)
                    {
                        if (dr["SignUpType"].ToSafeString() != "")
                        {
                            if (dr["SignUpType"].ToSafeString() == Guid.Empty.ToSafeString())
                            {
                                dr["SignUpType"] = "全部";
                            }
                        }
                        if (dr["SpecialityKindsName"].ToSafeString() == "")
                        {
                            dr["SpecialityKindsName"] = "全部";
                        }
                        if (dr["SpecialityKinds_DetailName"].ToSafeString() == "")
                        {
                            dr["SpecialityKinds_DetailName"] = "全部";
                        }
                    }
                }
                return result;
            }
        }

        internal TB_Rule_CalculateScoreDetail GetExamCalculateTypeFormModel_Detail(string strCalculateScoreDetailID)
        {
            return baseService.GetExamCalculateTypeFormModel_Detail(strCalculateScoreDetailID).ToList<TB_Rule_CalculateScoreDetail>();
        }

        internal bool SaveExamCalculateTypeForm_Detail(TB_Rule_CalculateScoreDetail model)
        {
            string strJson = model.ToJson();
            var obj = baseService.SaveExamCalculateTypeForm_Detail(strJson);
            var result = obj.ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        internal bool DeleteExamCalculateTypeForm_Detail(string strID)
        {
            var obj = baseService.DeleteExamCalculateTypeForm_Detail(strID);
            var result = obj.ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }
        #endregion

        #region 考场相关
        internal DataTable GetExamEntretenimientohRoomTable()
        {
            using (DataTable result = baseService.GetExamEntretenimientohRoomTable().ToDataTable())
            {
                if (result != null)
                {
                    result.Columns.Add("EntretenimientohExamRoomName");
                    string strBindName = string.Empty;
                    foreach (DataRow dr in result.Rows)
                    {
                        strBindName = dr["ExamPlaceName"].ToSafeString() + "-" + dr["SpecialityKindsName"].ToSafeString() + "-"
                            + dr["ExamLevelName"].ToSafeString() + "-" + dr["ExamRoomName"].ToSafeString();
                        dr["EntretenimientohExamRoomName"] = strBindName;
                    }
                }
                return result;
            }
        }

        internal DataTable GetRoomMacDataTable(string strRoomMacExamRoomNO, string strRoomMacNO, string strRoomMacExamYear)
        {
            return baseService.GetRoomMacDataTable(strRoomMacExamRoomNO, strRoomMacNO, strRoomMacExamYear).ToDataTable();
        }

        internal DataTable GetExamEntretenimientohTable(string strYear, string strExamPlaceID, string strSpecialityKindsNO, string strExamLevel)
        {
            using (DataTable result = baseService.GetExamEntretenimientohTable(strYear, strExamPlaceID, strSpecialityKindsNO, strExamLevel).ToDataTable())
            {
                if (result != null)
                {
                    result.Columns.Add("EntretenimientohName");
                    string strBindName = string.Empty;
                    foreach (DataRow dr in result.Rows)
                    {
                        strBindName = dr["ExamPlaceName"].ToSafeString() + "-" + dr["SpecialityKindsName"].ToSafeString() + "-" + dr["ExamLevelName"].ToSafeString() + "-" + dr["ExamScoreTypeName"].ToSafeString();
                        dr["EntretenimientohName"] = strBindName;
                    }
                }
                return result;
            }
        }

        internal DataTable GetExamRoomTable(string strEntretenimientohID, string strYear)
        {
            return baseService.GetExamRoomTable(strEntretenimientohID, strYear).ToDataTable();
        }

        internal TB_Exam_ExamRoom GetExamRoomModel(string strExamRoomNO)
        {
            return baseService.GetExamRoomModel(strExamRoomNO).ToList<TB_Exam_ExamRoom>();
        }

        internal bool SaveExamRoom(TB_Exam_ExamRoom model)
        {
            string strJson = model.ToJson();
            var obj = baseService.SaveExamRoom(strJson);
            var result = obj.ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        internal bool SaveExamRoomMacMapping(TB_Exam_ExamRoomMacMapping model)
        {
            string strJson = model.ToJson();
            var obj = baseService.SaveExamRoomMacMapping(strJson);
            var result = obj.ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }
        internal bool SaveExamRoomMacMapping(List<TB_Exam_ExamRoomMacMapping> list)
        {
            string strJson = list.ToJson();
            var obj = baseService.SaveExamRoomMacMappingList(strJson);
            var result = obj.ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        internal bool DeleteExamRoomMacMapping(List<string> list)
        {
            try
            {
                foreach (string strData in list)
                {
                    string[] DataS = strData.Split(',');
                    if (DataS.Length == 3)
                    {
                        baseService.DeleteExamRoomMacMapping(DataS[0], DataS[1], DataS[2]);
                    }
                }
                DevHelper.ShowErrorMessageBox("删除成功");
                return true;
            }
            catch (Exception ex)
            {
                DevHelper.ShowErrorMessageBox("删除失败:" + ex.Message);
                return false;
            }
        }

        internal bool DeleteExamRoomMacMapping(string strExamRoomNO, string strMac, string strYear)
        {
            var obj = baseService.DeleteExamRoomMacMapping(strExamRoomNO, strMac, strYear);
            var result = obj.ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }
        #endregion

        #region 评分方式
        internal DataTable GetExamScoreTypeTable(string strYear)
        {
            DevHelper.ShowWaiting();
            using (DataTable result = baseService.GetExamScoreTypeTable(strYear).ToDataTable())
            {
                if (result != null)
                {
                    foreach (DataRow dr in result.Rows)
                    {
                        dr["PadScoreTpye"] = Utility.Const.ConstAppConfig.DicPadScoreType[dr["PadScoreTpye"].ToSafeString()];
                        if (dr["IsPad"].ToSafeString() == "1")
                        {
                            dr["IsPad"] = "是";
                        }
                        else
                        {
                            dr["IsPad"] = "否";
                        }
                    }
                }
                return result;
            }
        }

        internal TB_Sys_ExamScoreType GetExamScoreTypeModel(string strExamScoreTypeID)
        {
            return baseService.GetExamScoreTypeModel(strExamScoreTypeID).ToList<TB_Sys_ExamScoreType>();
        }

        internal bool SaveExamScoreType(TB_Sys_ExamScoreType model)
        {
            string strJson = model.ToJson();
            var result = baseService.SaveExamScoreType(strJson).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        internal bool DeleteExamScoreType(string strExamScoreTypeID)
        {
            var result = baseService.DeleteExamScoreType(strExamScoreTypeID).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        internal DataTable GetExamScoreTypeTable_Detail(string strExamScoreTypeID)
        {
            return baseService.GetExamScoreTypeTable_Detail(strExamScoreTypeID).ToDataTable();
        }

        internal TB_Sys_ExamScoreTypeItem GetExamScoreTypeModel_Detail(string strTypeItemID)
        {
            return baseService.GetExamScoreTypeModel_Detail(strTypeItemID).ToList<TB_Sys_ExamScoreTypeItem>();
        }

        internal bool SaveExamScoreType_Detail(TB_Sys_ExamScoreTypeItem model)
        {
            string strJson = model.ToJson();
            var result = baseService.SaveExamScoreType_Detail(strJson).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        internal bool DeleteExamScoreType_Detail(string strTypeItemID)
        {
            var result = baseService.DeleteExamScoreType_Detail(strTypeItemID).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }
        #endregion

        #region 考试方式
        public bool DeleteExamType(string SpecialityKindsNO)
        {
            var result = baseService.DeleteExamType(SpecialityKindsNO).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }
        internal DataTable GetExamTypeTable(string strJson)
        {
            DevHelper.ShowWaiting();
            using (DataTable result = baseService.GetExamTypeTable(strJson).ToDataTable())
            {
                if (result != null)
                {
                    foreach (DataRow dr in result.Rows)
                    {
                        if (dr["IsActive"].ToSafeString() == "1")
                        {
                            dr["IsActive"] = "是";
                        }
                        else
                        {
                            dr["IsActive"] = "否";
                        }
                    }
                }
                return result;
            }
        }
        internal bool SaveExamType(TB_Dic_ExamType model)
        {
            string strJson = model.ToJson();
            var result = baseService.SaveExamType(strJson).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        internal TB_Dic_ExamType GetExamTypeModel(string strDicNO)
        {
            return baseService.GetExamTypeModel(strDicNO).ToList<TB_Dic_ExamType>();
        }
        #endregion

        #region  专业、级别、考试方式 关联
        internal DataTable GetSpecialityLevelExamTypeMappingNameTable(string SpecialityKindsNO, string ExamLevel, string ExamYear)
        {
            return baseService.GetSpecialityLevelExamTypeMappingNameTable(SpecialityKindsNO, ExamLevel, ExamYear).ToDataTable();
        }

        internal DataTable GetSpecialityLevelExamTypeMappingTable(string ExamYear)
        {
            return baseService.GetSpecialityLevelExamTypeMappingTable(ExamYear).ToDataTable();
        }

        internal TB_Sys_SpecialityLevelExamTypeMapping GetSpecialityLevelExamTypeMappingModel(string strSpecialityLevelMappingID)
        {
            return baseService.GetSpecialityLevelExamTypeMappingModel(strSpecialityLevelMappingID).ToList<TB_Sys_SpecialityLevelExamTypeMapping>();
        }

        internal bool SaveSpecialityLevelExamTypeMapping(TB_Sys_SpecialityLevelExamTypeMapping model)
        {
            string strJson = model.ToJson();
            var result = baseService.SaveSpecialityLevelExamTypeMapping(strJson).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        internal bool DeleteSpecialityLevelExamTypeMapping(string strSpecialityLevelMappingID, string SpecialityKindsNO, string ExamLevel)
        {
            var result = baseService.DeleteSpecialityLevelExamTypeMapping(strSpecialityLevelMappingID, SpecialityKindsNO, ExamLevel).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }


        internal bool SaveSpecialityLevelMapping(List<TB_Sys_SpecialityLevelMapping> list)
        {
            var result = baseService.SaveSpecialityLevelMapping(list.ToJson()).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        internal DataTable GetSpecialityLevelMapping(string strSpecialityKindsNO)
        {
            return baseService.GetSpecialityLevelMapping(strSpecialityKindsNO).ToDataTable();
        }
        #endregion

        #region 考点专业相关
        internal DataTable GetExamPlaceSpecialityKindsMappingTable(string strExamPlaceNO, string strSpecialityKindsNO)
        {
            DevHelper.ShowWaiting();
            using (DataTable result = baseService.GetExamPlaceSpecialityKindsMappingTable(strExamPlaceNO, strSpecialityKindsNO).ToDataTable())
            {
                if (result != null)
                {
                    foreach (DataRow dr in result.Rows)
                    {
                        if (dr["IsOnlineReg"].ToSafeString() == "1")
                        {
                            dr["IsOnlineReg"] = "是";
                        }
                        else
                        {
                            dr["IsOnlineReg"] = "否";
                        }
                        if (dr["IsOpen"].ToSafeString() == "1")
                        {
                            dr["IsOpen"] = "是";
                        }
                        else
                        {
                            dr["IsOpen"] = "否";
                        }
                    }
                }
                return result;
            }
        }

        internal TB_Sys_ExamPlaceSpecialityKindsMapping GetExamPlaceSpecialityKindsMappingModel(string strExamPlaceSpecialityKindsMappingID)
        {
            return baseService.GetExamPlaceSpecialityKindsMappingModel(strExamPlaceSpecialityKindsMappingID).ToList<TB_Sys_ExamPlaceSpecialityKindsMapping>();
        }

        internal bool SaveExamPlaceSpecialityKindsMapping(TB_Sys_ExamPlaceSpecialityKindsMapping model)
        {
            string strJson = model.ToJson();
            var result = baseService.SaveExamPlaceSpecialityKindsMapping(strJson).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        internal bool DeleteExamPlaceSpecialityKindsMapping(string strExamPlaceSpecialityKindsMappingID)
        {
            var result = baseService.DeleteExamPlaceSpecialityKindsMapping(strExamPlaceSpecialityKindsMappingID).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        internal DataTable GetExamPlaceSpecialityKindsGroupTable(string strExamPlaceSpecialityKindsMappingID, string strExamPlaceNO,
            string strSpecialityKindsNO, string strExamLevel)
        {
            DevHelper.ShowWaiting();
            using (DataTable result = baseService.GetExamPlaceSpecialityKindsGroupTable(strExamPlaceSpecialityKindsMappingID, strExamPlaceNO, strSpecialityKindsNO, strExamLevel).ToDataTable())
            {
                if (result != null)
                {
                    foreach (DataRow dr in result.Rows)
                    {
                        if (dr["IsActive"].ToSafeString() == "1")
                        {
                            dr["IsActive"] = "是";
                        }
                        else
                        {
                            dr["IsActive"] = "否";
                        }
                    }

                }
                return result;
            }
        }

        internal TB_Sys_ExamPlaceSpecialityKindsGroupMapping GetExamPlaceSpecialityKindsGroupMappingModel(string strExamPlaceSpecialityKindsMappingID, string strGroupNo)
        {
            return baseService.GetExamPlaceSpecialityKindsGroupMappingModel(strExamPlaceSpecialityKindsMappingID, strGroupNo).ToList<TB_Sys_ExamPlaceSpecialityKindsGroupMapping>();
        }

        internal bool SaveExamPlaceSpecialityKindsGroupMapping(TB_Sys_ExamPlaceSpecialityKindsGroupMapping model)
        {
            string strJson = model.ToJson();
            var result = baseService.SaveExamPlaceSpecialityKindsGroupMapping(strJson).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        internal bool DeleteExamPlaceSpecialityKindsGroupMapping(string strExamPlaceSpecialityKindsMappingID, string strGroupNo)
        {
            var result = baseService.DeleteExamPlaceSpecialityKindsGroupMapping(strExamPlaceSpecialityKindsMappingID, strGroupNo).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }
        #endregion

        #region Pad相关设置
        public DataTable GetDicPadShowFiledAllTable(string strIsWhere)
        {
            return baseService.GetDicPadShowFiledAllTable(strIsWhere).ToDataTable();
        }

        public DataTable GetDicPadShowFiledShowTable()
        {
            return baseService.GetDicPadShowFiledShowTable().ToDataTable();
        }

        public bool SaveDicPadFiledShow(List<TB_Dic_PadFiledShow> list)
        {
            var result = baseService.SaveDicPadFiledShow(list.ToJson()).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        public bool DeleteDicPadFiledShow(List<string> list)
        {
            var result = baseService.DeleteDicPadFiledShow(list.ToJson()).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        public bool SortDicPadFiledShow(Dictionary<string, string> dicList)
        {
            var result = baseService.SortDicPadFiledShow(dicList.ToJson()).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        public bool SavePadExamScorePageSetting(TB_Dic_PadExamScorePageSetting model)
        {
            var result = baseService.SavePadExamScorePageSetting(model.ToJson()).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        public bool SavePadExamScorePageSettingDetail(List<TB_Dic_PadExamScorePageSetting_Detail> list)
        {
            var result = baseService.SavePadExamScorePageSettingDetail(list.ToJson()).ToList<JsonMessage>();
            if (result.State.ToLower() == "false")
            {
                DevHelper.ShowErrorMessageBox(result.Msg);
                return false;
            }
            else
            {
                DevHelper.ShowInfoMessageBox(result.Msg);
                return true;
            }
        }

        public TB_Dic_PadExamScorePageSetting GetPadExamScorePageSettingModel(string strPadExamScorePageSettingType)
        {
            return baseService.GetPadExamScorePageSettingModel(strPadExamScorePageSettingType).ToList<TB_Dic_PadExamScorePageSetting>();
        }

        public List<TB_Dic_PadExamScorePageSetting_Detail> GetPadExamScorePageSettingDetailList(string strPadExamScorePageSettingID)
        {
            return baseService.GetPadExamScorePageSettingDetailList(strPadExamScorePageSettingID).ToList<List<TB_Dic_PadExamScorePageSetting_Detail>>();
        }
        #endregion
    }
}
